<template>
  <div>
    <div class="z-flex-in">
      <div></div>
      <div class="m-btn-box">
        <el-button type="primary" @click="addNewRoute()">新建按钮</el-button>
        <!-- <el-button type="primary">关联数据</el-button> -->
      </div>
    </div>
    <el-table :data="tableList" stripe border style="width: 100%">
      <el-table-column prop="router_name" label="序号" width="50px">
        <template slot-scope="scope">{{
          (pageIndex - 1) * 10 + scope.$index + 1
        }}</template>
      </el-table-column>
      <el-table-column prop="page_name" label="页面资源名称"></el-table-column>
      <el-table-column
        prop="btn_key"
        label="按钮值"
        width="100px"
      ></el-table-column>
      <el-table-column
        prop="handle_class"
        label="资源权限验证类"
      ></el-table-column>
      <el-table-column prop="description" label="描述"></el-table-column>
      <el-table-column prop="description" label="按钮类型">
        <template slot-scope="scope">
          <span>{{ scope.row.button_type | G(buttonTyoeArr) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop label="操作" width="80px">
        <template slot-scope="scope">
          <el-button @click="setData(scope.row)" type="text" size="small"
            >查看</el-button
          >
          <el-popconfirm
            title="确定删除该项？"
            @onConfirm="deleteRow(scope.row)"
          >
            <el-button slot="reference" type="text" size="small"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <!-- {{vueNodeData}} -->
  </div>
</template>
<script>
import { getBtnNodeTargetList, deleteButtonTreeNodeTarget } from '@/api/api.js'
export default {
  data () {
    return {
      tableList: [],
      nodeId: '',
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0
    }
  },
  watch: {
    'vueNodeData.node_id' (val, oldVal) {
      this.nodeId = val
      this.pageIndex = 1
      this.getTableList()
      console.log(val)
    }
  },
  props: ['vueNodeData', 'buttonTyoeArr'],
  filters: {
    G (value, data) {
      let res = data.filter(function (item) {
        return item.t_id === value
      })
      if (res.length) {
        return res[0].display_value
      } else {
        return ''
      }
    }
  },
  methods: {
    async deleteRow (e) {
      console.log()
      let res = await deleteButtonTreeNodeTarget({
        target_id: e.id
      })
      if (res[0]) {
        return
      }
      this.getTableList()
    },
    setData (e) {
      this.$emit('setFormData', e)
    },
    addNewRoute () {
      this.$emit('routerConfigShowC', true)
    },
    async getTableList () {
      let res = await getBtnNodeTargetList({
        node_id: this.nodeId,
        by_page: {
          currPage: this.pageIndex,
          pageSize: this.pageSize
          // condition: this.condition
        }
      })
      if (res[0]) {
        return
      }
      this.tableList = res[1].data.list
      this.totalPage = res[1].data.totalCount
      console.log(res[1])
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getTableList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getTableList()
    }
  }
}
</script>
<style scoped>
.z-flex-in {
  display: flex;
  justify-content: space-between;
}
.m-btn-box {
  margin-bottom: 10px;
}
</style>
